/*****************************************
 * 	@Description : Comet TEST
 *	@FileName 	 : comet.js
 * 	@Author   	 : He Chang Min 
 * 	@Date     	 : 2009-03-05
 * 	@Comment  	 : 
 ******************************************/

var WebApp = 
{
	//程序入口函数
	WebMain : function()
  	{
  		var ajax = new Ajax.Request(WebApp._url_, 
		{
			method: 'get',
			parameters: { 'timestamp' : WebApp._timestamp_ },
		    onSuccess: function(transport) 
			{
		      	var response = transport.responseText.evalJSON();
		        WebApp._timestamp_ = response['timestamp'];
		        WebApp.handleResponse(response);
		        WebApp._noerror_ = true;
		    },
		    onComplete: function(transport) 
			{
	        	if (!WebApp._noerror_)
				{
	        		setTimeout(WebApp.WebMain, 5000); 
				}else
	       	 	{ 
					setTimeout(WebApp.WebMain, 10); 
				}
	        	WebApp._noerror_ = false;
	      	}
		});
	},
  	handleResponse : function(response)
  	{
    	$('content').innerHTML += '<div><span style="font-weight:bold;">' +response['user']+"</span> "+ response['msg'] + '</div>';
  	},
  	doRequest : function(request,qwe)
  	{
    	new Ajax.Request(WebApp._url_, 
		{
      		method 		: 'get',
      		parameters  : { 
			'msg' : request,
			'user': qwe
			}
    	});
  	},
  	//成员属性
  	_timestamp_ 	: 0,
	_url_		  	: 'comet',
  	_noerror_	  	: true  
}
